import { fileURLToPath, URL } from "node:url";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
// 自动导入
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

// https://vite.dev/config/
export default defineConfig({
  base: "./",
  plugins: [
    vue(),
    AutoImport({
      imports: ["vue", "vue-router", "vuex"],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  css: {
    preprocessorOptions: {
      scss: {
        // 自动导入全局变量和混合（多个文件用逗号分隔）
        // additionalData: `@import "@/assets/scss/variables.scss";`,
      },
    },
  },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  // 开发服务器配置
  server: {
    // 端口号
    port: 8081,
    // 监听所有地址
    host: "0.0.0.0",
    // 启用 https
    // https: false,
    // 代理配置
    proxy: {
      // 匹配以 /api 或具体路径开头的请求
      "/api": {
        target: "http://files.yuianweb.com", // 目标服务器地址
        changeOrigin: true, // 允许跨域
        pathRewrite: {
          "^/api": "", // 重写路径（去掉 /api 前缀）
        },
      },
    },
  },
});
